/**
 * Created by LiuDan on 2017/07/12.
 * 第三方登陆.js
 */
;(function($){
    var referUrl=window.location.href;
    //dom获取
    $.dom={
        qqLogin:$('.qq-login'),
        wxLogin:$('.weixin-login'),
        wbLogin:$('.weibo-login')
    },
        $.common={
            getString:function(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return decodeURIComponent(r[2]);
                return null;
            }
        },
        $.thirdLogin={
            refer:function(url){
                if(referUrl.indexOf('login')!=-1 || referUrl.indexOf('register')!=-1){
                    var refer=$.common.getString('refer')?encodeURIComponent(encodeURI($.common.getString('refer'))):''
                    if(refer){
                        window.location.href=url+refer;
                    }else{
                        window.location.href=url+basePathOnline;
                    }
                }else{
                    window.location.href= url+encodeURIComponent(encodeURI(referUrl));
                }
            },
            //绑定事件
            bindEvent:function(){
                //qq登陆
                $.dom.qqLogin.click(function(){
                    $.thirdLogin.refer(basePathOnline+'/online/user/qq_login?refer=')
                })
                //微信登陆
                $.dom.wxLogin.click(function(){
                    $.thirdLogin.refer(basePathOnline+'/online/user/wechat_login?refer=')
                })
                //微博登陆
                $.dom.wbLogin.click(function(){
                    $.thirdLogin.refer(basePathOnline+'/online/user/weibo_login?refer=')
                })
            },

            init:function(){
                $.thirdLogin.bindEvent()
            }
        }
    $.thirdLogin.init()
})(jQuery)